{smcl}
{com}{sf}{ul off}{txt}{.-}
      name:  {res}<unnamed>
       {txt}log:  {res}C:\Users\myogo\Princeton Dropbox\Motohiro Yogo\Koijen Yogo - International\JPE\Replication\Code\1 Data\Restatement.smcl
  {txt}log type:  {res}smcl
 {txt}opened on:  {res}31 Oct 2025, 09:17:37
{txt}
{com}. /* Define local and global variables */
> 
> local directory = "../../Data/Global Capital Allocation";
{txt}
{com}. do global;
{txt}
{com}. /* global.do (STATA)
>         Define global variables in "Data".
>         by Ralph Koijen & Motohiro Yogo */
. 
. #delimit ;
{txt}delimiter now ;
{com}. clear all;
{res}{txt}
{com}. global year_min = 2003;
{txt}
{com}. global year_max = 2020;
{txt}
{com}. global small = 5e-4;
{txt}
{com}.         /* Minimum reportable threshold for CPIS */

{txt}end of do-file

{com}. /* Step 1: Prepare countries */
> 
> u country Yeuro using Countries, clear;
{txt}
{com}. /* Add currency reserves */
> 
> input;

     {txt}  country     Yeuro
243{com}. _CR .;
{txt}244{com}. end;
{txt}
{com}. /* Construct variables */
> 
> gen Investor = "EMU" if !missing(Yeuro);
{txt}(224 missing values generated)

{com}. replace Investor = "World" if missing(Yeuro);
{txt}variable {bf}{res}Investor{sf}{txt} was {bf}{res}str3{sf}{txt} now {bf}{res}str5{sf}
{txt}(224 real changes made)

{com}. drop Yeuro;
{txt}
{com}. /* Save data */
> 
> tempfile Countries;
{txt}
{com}. save `Countries';
{txt}{p 0 4 2}
file {bf}
C:\Users\myogo\AppData\Local\Temp\ST_9840_000001.tmp{rm}
saved
as .dta format
{p_end}

{com}. /* Step 2: Construct restatement matrices for issuances */
> 
> /* Load restatement matrices */
> 
> u Methodology Year Asset_Class Destination Destination_Restated Value
>         if Methodology==3                       /* Issuance */
>         & inrange(Year,$year_min,$year_max)
>         & inlist(Asset_Class,1,3)       /* 1 = All Bonds, 3 = Common Equity */
>         using "`directory'/Restatement_Matrices", clear;
{txt}
{com}. drop Methodology;
{txt}
{com}. /* Rename variables */
> 
> rename Year year;
{res}{txt}
{com}. rename Destination Counterpart;
{res}{txt}
{com}. rename Destination_Restated counterpart;
{res}{txt}
{com}. /*
> /* Merge country code */
> 
> merge m:1 Counterpart using Countries,
>         keepusing(Itax)
>         nogen keep(match);
> 
> /* Keep tax havens only */
> 
> keep if Itax;
> 
> drop Itax;
> */
> /* Correct rounding error */
> 
> egen TValue = total(Value), missing by(year Counterpart Asset_Class);
{txt}
{com}. replace Value = Value/TValue;
{txt}(20,486 real changes made)

{com}. drop TValue;
{txt}
{com}. /* Expand to ST and LT debt */
> 
> expand 3 if Asset_Class==1;
{txt}(21,032 observations created)

{com}. bysort year Counterpart counterpart Asset_Class: gen byte type = Asset_Class+(Asset_Class==1)*(_n-2);
{txt}
{com}. drop Asset_Class;
{txt}
{com}. /* Extrapolate backward */
> 
> egen int Myear = min(year);
{txt}
{com}. gen byte obs = year-$year_min+1 if year==Myear;
{txt}(39,467 missing values generated)

{com}. expand obs;
{txt}(39,467 missing counts ignored; observations not deleted)
(14,932 observations created)

{com}. bysort year Counterpart counterpart type: replace year = year-_n+1;
{txt}(14,932 real changes made)

{com}. drop Myear obs;
{txt}
{com}. /* Extrapolate forward */
> 
> egen int Myear = max(year);
{txt}
{com}. gen byte obs = $year_max-year+1 if year==Myear;
{txt}(54,031 missing values generated)

{com}. expand obs;
{txt}(54,031 missing counts ignored; observations not deleted)
(12,303 observations created)

{com}. bysort year Counterpart counterpart type: replace year = year+_n-1;
{txt}(12,303 real changes made)

{com}. drop Myear obs;
{txt}
{com}. /* Label variables */
> 
> order year Counterpart counterpart type;
{txt}
{com}. label var year                  "Year";
{txt}
{com}. label var Counterpart   "Issuer country by residency";
{txt}
{com}. label var counterpart   "Issuer country by nationality";
{txt}
{com}. label var type                  "Asset type";
{txt}
{com}. label var Value                 "Restatement share from residency to nationality";
{txt}
{com}. label define type_label
>         0 "All debt"
>         1 "Short-term debt"
>         2 "Long-term debt"
>         3 "Equity", replace;
{txt}
{com}. label val type type_label;
{txt}
{com}. /* Save data */
> 
> sort year Counterpart counterpart type;
{txt}
{com}. save Restatement_issuance, replace;
{txt}{p 0 4 2}
file {bf}
Restatement_issuance.dta{rm}
saved
{p_end}

{com}. /* Step 3: Construct share in common equity */
> 
> /* Load restated bilateral portfolios */
> 
> u Methodology Year Investor Asset_Class Issuer Position_Residency Estimated_Common_Equity
>         if inrange(Year,$year_min,$year_max)
>         & Asset_Class==4        /* Common Equity and Fund Shares */
>         & Position_Residency>0
>         & !missing(Estimated_Common_Equity)
>         using "`directory'/Restated_Bilateral_External_Portfolios", clear;
{txt}
{com}. drop Asset_Class;
{txt}
{com}. /* Keep best methodology */
> 
> egen byte best = min(Methodology), by(Year Investor);
{txt}
{com}. keep if Methodology==best;
{txt}(2,311 observations deleted)

{com}. drop Methodology best;
{txt}
{com}. /* Rename variables */
> 
> rename Year year;
{res}{txt}
{com}. rename Issuer Counterpart;
{res}{txt}
{com}. /* Construct variables */
> 
> gen byte type = 3;
{txt}
{com}. gen Scommon = min(Estimated_Common_Equity/Position_Residency,1);
{txt}
{com}. drop Estimated_Common_Equity Position_Residency;
{txt}
{com}. /* Merge country code */
> 
> joinby Investor using `Countries', unmatched(master);
{txt}
{com}. replace country = Investor if _merge==1;
{txt}(9,031 real changes made)

{com}. drop Investor _merge;
{txt}
{com}. /* Extrapolate backward */
> 
> egen int Myear = min(year), by(country);
{txt}
{com}. gen byte obs = year-$year_min+1 if year==Myear;
{txt}(17,762 missing values generated)

{com}. expand obs;
{txt}(17,762 missing counts ignored; observations not deleted)
(6,789 observations created)

{com}. bysort year country Counterpart type: replace year = year-_n+1;
{txt}(6,789 real changes made)

{com}. drop Myear obs;
{txt}
{com}. /* Extrapolate forward */
> 
> egen int Myear = max(year), by(country);
{txt}
{com}. gen byte obs = $year_max-year+1 if year==Myear;
{txt}(24,398 missing values generated)

{com}. expand obs;
{txt}(24,398 missing counts ignored; observations not deleted)
(2,583 observations created)

{com}. bysort year country Counterpart type: replace year = year+_n-1;
{txt}(2,583 real changes made)

{com}. drop Myear obs;
{txt}
{com}. /* Label variables */
> 
> order year country Counterpart type;
{txt}
{com}. label var year                  "Year";
{txt}
{com}. label var country               "Investor country";
{txt}
{com}. label var Counterpart   "Issuer country by residency";
{txt}
{com}. label var type                  "Asset type";
{txt}
{com}. label var Scommon               "Share in common equity";
{txt}
{com}. label define type_label
>         1 "Short-term debt"
>         2 "Long-term debt"
>         3 "Equity";
{txt}
{com}. label val type type_label;
{txt}
{com}. /* Save data */
> 
> sort year country Counterpart type;
{txt}
{com}. save Restatement_equity, replace;
{txt}{p 0 4 2}
file {bf}
Restatement_equity.dta{rm}
saved
{p_end}

{com}. /* Step 4: Construct asset class shares for USA */
> 
> /* Load restated bilateral portfolios */
> 
> u Methodology Year Investor Asset_Class Issuer Position_Residency
>         if inrange(Year,$year_min,$year_max)
>         & Investor=="USA"
>         & inlist(Asset_Class,2,5,6)     /* 2 = Asset-Backed Securities, 5 = Corporate Bonds, 6 = Government Bonds */
>         using "`directory'/Restated_Bilateral_External_Portfolios", clear;
{txt}
{com}. /* Keep best methodology */
> 
> egen byte best = min(Methodology), by(Year Asset_Class);
{txt}
{com}. keep if Methodology==best;
{txt}(6,050 observations deleted)

{com}. drop Methodology best;
{txt}
{com}. /* Rename variables */
> 
> rename Year year;
{res}{txt}
{com}. rename Issuer Counterpart;
{res}{txt}
{com}. /* Fix variables */
> 
> replace Asset_Class = Asset_Class-1 if Asset_Class>=5;
{txt}(6,776 real changes made)

{com}. /* Construct variables */
> 
> egen TPosition_Residency = total(Position_Residency), missing by(year Counterpart);
{txt}
{com}. gen weight = Position_Residency/TPosition_Residency;
{txt}(4,044 missing values generated)

{com}.         /* Value weighted if available */
> replace weight = 1/3 if TPosition_Residency==0;
{txt}(4,044 real changes made)

{com}.                         /* Equal weighted otherwise */
> 
> drop Position_Residency TPosition_Residency;
{txt}
{com}. /* Save data */
> 
> tempfile USA;
{txt}
{com}. save `USA';
{txt}{p 0 4 2}
file {bf}
C:\Users\myogo\AppData\Local\Temp\ST_9840_000002.tmp{rm}
saved
as .dta format
{p_end}

{com}. /* Step 5: Construct restatement matrices for bilteral positions */
> 
> /* Load restatement matrices */
> 
> u Methodology Year Investor Asset_Class Destination Destination_Restated Value
>         if inrange(Year,$year_min,$year_max)
>         & (Investor=="USA" | Asset_Class!=4)    /* 4 = Corporate Bonds */
>         using "`directory'/Restatement_Matrices", clear;
{txt}
{com}. /* Keep best methodology */
> 
> egen byte best = min(Methodology), by(Year Investor Asset_Class);
{txt}
{com}. keep if Methodology==best;
{txt}(3,035,296 observations deleted)

{com}. drop Methodology best;
{txt}
{com}. /* Rename variables */
> 
> rename Year year;
{res}{txt}
{com}. rename Destination Counterpart;
{res}{txt}
{com}. rename Destination_Restated counterpart;
{res}{txt}
{com}. /*
> /* Merge country code */
> 
> merge m:1 Counterpart using Countries,
>         keepusing(Itax)
>         nogen keep(match);
> 
> /* Keep tax havens only */
> 
> keep if Itax;
> 
> drop Itax;
> */
> /* Merge asset class shares for USA */
> 
> merge m:1 year Investor Counterpart Asset_Class using `USA';
{res}{txt}(label {bf:{txt}_Asset_Class} already defined)

{col 5}Result{col 33}Number of obs
{col 5}{hline 41}
{col 5}Not matched{col 30}{res}         136,273
{txt}{col 9}from master{col 30}{res}         133,459{txt}  (_merge==1)
{col 9}from using{col 30}{res}           2,814{txt}  (_merge==2)

{col 5}Matched{col 30}{res}          13,758{txt}  (_merge==3)
{col 5}{hline 41}

{com}. /* Assume nationality is same as residency if unknown */
> 
> replace counterpart = Counterpart if _merge==2;
{txt}(2,814 real changes made)

{com}. replace Value = 1 if _merge==2;
{txt}(2,814 real changes made)

{com}. drop _merge;
{txt}
{com}. /* Construct "All Bonds" for USA */
> 
> egen TValue = total(weight*Value) if Investor=="USA" & inlist(Asset_Class,2,4,5), missing by(year Investor Counterpart counterpart);
{txt}(133,459 missing values generated)

{com}. replace Value = TValue if Investor=="USA" & inlist(Asset_Class,2,4,5) & !missing(TValue);
{txt}(8,718 real changes made)

{com}. replace Asset_Class = 1 if Investor=="USA" & inlist(Asset_Class,2,4,5);
{txt}(16,614 real changes made)

{com}. bysort year Investor Counterpart counterpart Asset_Class: keep if _n==1;
{txt}(7,749 observations deleted)

{com}. drop weight TValue;
{txt}
{com}. /* Correct rounding error */
> 
> egen TValue = total(Value), missing by(year Investor Counterpart Asset_Class);
{txt}
{com}. replace Value = Value/TValue;
{txt}(106,128 real changes made)

{com}. drop TValue;
{txt}
{com}. /* Merge country code */
> 
> joinby Investor using `Countries', unmatched(master);
{txt}
{com}. replace country = Investor if _merge==1;
{txt}(99,919 real changes made)

{com}. /* Drop if country-specific restatement available */
> 
> sort year country _merge;
{txt}
{com}. by year country: drop if _merge[1]==1 & _merge==3;
{txt}(177,344 observations deleted)

{com}. drop Investor _merge;
{txt}
{com}. /* Expand to ST and LT debt */
> 
> expand 2 if Asset_Class==1, gen(duplicate);
{txt}(2,494,567 observations created)

{com}. gen byte type = Asset_Class+duplicate;
{txt}
{com}. drop Asset_Class duplicate;
{txt}
{com}. /* Extrapolate backward */
> 
> egen int Myear = min(year), by(country);
{txt}
{com}. gen byte obs = year-$year_min+1 if year==Myear;
{txt}(7,098,691 missing values generated)

{com}. expand obs;
{txt}(7,098,691 missing counts ignored; observations not deleted)
(2,671,152 observations created)

{com}. bysort year country Counterpart counterpart type: replace year = year-_n+1;
{txt}(2,671,152 real changes made)

{com}. drop Myear obs;
{txt}
{com}. /* Extrapolate forward */
> 
> egen int Myear = max(year), by(country);
{txt}
{com}. gen byte obs = $year_max-year+1 if year==Myear;
{txt}(9,730,043 missing values generated)

{com}. expand obs;
{txt}(9,730,043 missing counts ignored; observations not deleted)
(1,981,635 observations created)

{com}. bysort year country Counterpart counterpart type: replace year = year+_n-1;
{txt}(1,981,635 real changes made)

{com}. drop Myear obs;
{txt}
{com}. /* Label variables */
> 
> order year country Counterpart counterpart type;
{txt}
{com}. label var year                  "Year";
{txt}
{com}. label var country               "Investor country";
{txt}
{com}. label var Counterpart   "Issuer country by residency";
{txt}
{com}. label var counterpart   "Issuer country by nationality";
{txt}
{com}. label var type                  "Asset type";
{txt}
{com}. label var Value                 "Restatement share from residency to nationality";
{txt}
{com}. label define type_label
>         1 "Short-term debt"
>         2 "Long-term debt"
>         3 "Equity";
{txt}
{com}. label val type type_label;
{txt}
{com}. /* Save data */
> 
> sort year country Counterpart counterpart type;
{txt}
{com}. save Restatement_bilateral, replace;
{txt}{p 0 4 2}
file {bf}
Restatement_bilateral.dta{rm}
saved
{p_end}

{com}. log close;
      {txt}name:  {res}<unnamed>
       {txt}log:  {res}C:\Users\myogo\Princeton Dropbox\Motohiro Yogo\Koijen Yogo - International\JPE\Replication\Code\1 Data\Restatement.smcl
  {txt}log type:  {res}smcl
 {txt}closed on:  {res}31 Oct 2025, 09:18:48
{txt}{.-}
{smcl}
{txt}{sf}{ul off}